package easy;

import java.util.Arrays;

/**
 * 1652. 拆炸弹
 * 创建时间：2024-05-22 15:42
 */
public class 拆炸弹_1652 {
    static class Solution {
        public int[] decrypt(int[] code, int k) {
            int n = code.length;
            int[] ans = new int[n];
            if (k != 0) {
                int l = k > 0 ? 1 : n + k;
                int r = k > 0 ? k : n - 1;
                int w = 0;
                for (int i = l; i <= r; i++) {
                    w += code[i];
                }
                for (int i = 0; i < n; i++) {
                    ans[i] = w;
                    w -= code[l];
                    l = (l + 1) % n;
                    r = (r + 1) % n;
                    w += code[r];
                }
            }
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution s = new Solution();
//        System.out.println(s.decrypt(new int[]{2, 4, 9, 3}, -2));
        System.out.println(s.decrypt(new int[]{5, 7, 1, 4}, 3));
    }
}
